<template>
	<view>
		<view class="header" style="">
			<!-- <basics></basics> -->
			<view class="box">
				<view class="cu-bar search bg-grey">
					<view class="search-form round">
						<text class="cuIcon-search"></text>
						<input @input="Input" :adjust-position="false" type="text" placeholder="请输入身份证查询" confirm-type="search" @confirm="get_wage"></input>
					</view>
					<view class="action">
						<button class="cu-btn bg-green shadow-blur round" @tap="get_wage">查询</button>
					</view>
				</view>
			</view>
			
			<basics v-if="BasicsEndState" :UserName="UserName" :EmployeeID="EmployeeID" :Avatar="Avatar"></basics>
			
		</view>
		
		
		<scroll-view scroll-y="true" style="">
			<preview :WageDatas="WageDatas" :state="PrevieWEndState" v-if="PrevieWState"></preview>
		</scroll-view>
		
	</view>
</template>

<script>
	import md5 from '../../js_sdk/md5.js';
	export default {
		data() {
			return {
				title: 'Hello',
				PageCur: '',
				InputText:'',
				WageDatas:{},
				DataFound:0,
				UserName:'',
				EmployeeID:'',
				BasicsEndState:false,
				Avatar:'',
				PrevieWEndState:false,
				PrevieWState:false
				
			}
		},
		onLoad() {

		},
		methods: {
			NavChange: function(e) {
				//this.PageCur = e.currentTarget.dataset.cur
			},
			LoadModal:function(e){
				//this.DataFound +=1;
				
				//this.DataFound%2 ? this.PageCur='basics' : this.PageCur='datanotfound';
				
				//this.PageCur='basics';
			},
			Input:function(event){
				this.InputText = event.target.value;
				
				
			},
			
			get_wage(){
				//console.log(md5(this.InputText));
				this.BasicsEndState = false;
				this.PrevieWState = false
				this.PrevieWEndState = false;
				uni.showLoading({
				  title: '处理中...'
				})
				// uni.hideLoading();

				uniCloud.callFunction({
					name:"get_wage",
					data:{wage:md5(this.InputText)}
				}).then((res) => {
					//函数处理成功///
					
					//ggg22223333
					
					
					
					
					var Data = res.result.data.sort(function (a, b) {
					    return Date.parse(b.Date) - Date.parse(a.Date);
					});
					
					if(Data.length){
						this.UserName = Data[0].UserName;
						this.EmployeeID = Data[0].EmployeeID;
						this.BasicsEndState = true;

						if(this.InputText[16]%2){
							this.Avatar = '../../static/male.png';
						}else{
							this.Avatar = '../../static/woman.png';
						}
						
						
						var Datas ={};

						for(let i in Data){
							
							if(undefined == Datas[Data[i]['Date']]){
								Datas[Data[i]['Date']] = {Date:Data[i]['Date'],Data:Array()};
							}
							Datas[Data[i]['Date']]['Data'].push([Data[i]['Type'],Data[i]['Amount'],Data[i]['_id']])
						};
					}else{
						this.UserName ='';
						this.EmployeeID = '';
						this.BasicsEndState = false;
					}
					this.PrevieWEndState = true;
					this.PrevieWState = true;
					this.WageDatas = Datas;
					uni.hideLoading();
				}).catch((err) => {
					//函数处理失败
					uni.hideLoading();
				})
				
			}
		}
	}
</script>

<style>
	.content {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}

	.logo {
		height: 200rpx;
		width: 200rpx;
		margin-top: 200rpx;
		margin-left: auto;
		margin-right: auto;
		margin-bottom: 50rpx;
	}

	.text-area {
		display: flex;
		justify-content: center;
	}

	.title {
		font-size: 36rpx;
		color: #8f8f94;
	}
</style>
